import {
  Entity,
  PrimaryGeneratedColumn,
  Column,
  CreateDateColumn,
  UpdateDateColumn,
  ManyToMany,
  JoinTable,
} from 'typeorm';
import { SysRole } from '../../sys-role/entities/sys-role.entity';

@Entity('sys_menu')
export class SysMenu {
  @PrimaryGeneratedColumn({ name: 'menu_id', comment: '菜单ID' })
  menu_id: number;

  @Column({ name: 'menu_name', comment: '菜单名称' })
  menu_name: string;

  @Column({ name: 'parent_id', comment: '父菜单ID' })
  parent_id: number;

  @Column({ name: 'order_num', comment: '显示顺序' })
  order_num: number;

  @Column({ name: 'path', comment: '路由地址' })
  path: string;

  @Column({ name: 'component', comment: '组件路径' })
  component: string;

  @Column({ name: 'query', comment: '路由参数' })
  query: string;

  @Column({ name: 'is_frame', comment: '是否为外链（0是 1否）' })
  is_frame: number;

  @Column({ name: 'is_cache', comment: '是否缓存（0缓存 1不缓存）' })
  is_cache: number;

  @Column({ name: 'menu_type', comment: '菜单类型（M目录 C菜单 F按钮）' })
  menu_type: string;

  @Column({ name: 'visible', comment: '菜单状态（0显示 1隐藏）' })
  visible: string;

  @Column({ name: 'status', comment: '菜单状态（0正常 1停用）' })
  status: string;

  @Column({ name: 'perms', comment: '权限标识' })
  perms: string;

  @Column({ name: 'icon', comment: '菜单图标' })
  icon: string;

  @Column({ name: 'create_by', comment: '创建者' })
  create_by: string;

  @CreateDateColumn({ name: 'create_time', comment: '创建时间' })
  create_time: Date;

  @UpdateDateColumn({ name: 'update_time', comment: '更新时间' })
  update_time: Date;

  @Column({ name: 'remark', comment: '备注' })
  remark: string;

  @ManyToMany(() => SysRole, (role) => role.menus)
  @JoinTable({
    name: 'sys_role_menu',
    joinColumn: {
      name: 'menu_id',
      referencedColumnName: 'menu_id',
    },
    inverseJoinColumn: {
      name: 'role_id',
      referencedColumnName: 'role_id',
    },
  })
  roles: SysRole[];

  children: SysMenu[];
}
